"""
连击数 计数逻辑
"""
import random


class LCalculator(object):

    def __init__(self):
        # 总连击数
        self.__total_num = 0
        # 连击缓存
        self.__Ls = list()
        # 当前连击
        self.__current = 0
        # 获取星币个数
        self.__currency = 0

    @property
    def all_lj(self):
        print(self.__Ls)
        return None

    @property
    def lian_ji(self):
        max_lianji = max(self.__Ls) or 0
        total = self.__total_num
        result = 'max: {}, total: {}, percent: {}%'.format(max_lianji, self.__total_num, round(max_lianji*100/total))
        print(result)
        return None

    @property
    def currency(self):

        for lj in self.__Ls:
            # 每连击五次获取5的倍数的星币
            get_currency = lj // 5
            self.__currency += get_currency
        print('currency: ', self.__currency)
        return None

    def play(self, end=False):
        # 控制正确率在80%
        correct_ls = [1, 1, 1, 1, 0]
        # correct_ls.extend([1,1,1,1,1,1,1,])
        current_ = random.choice(correct_ls)

        if current_ == 1:
            # 正确 当前连击+1
            self.__current += 1

        else:
            # 错误时，统计当前最大连击
            if self.__current > 1:
                self.__Ls.append(self.__current)
                self.__current = 0

        self.__total_num += 1

        if end:
            # 错误时，统计当前最大连击
            if self.__current > 1:
                self.__Ls.append(self.__current)
                self.__current = 0
                print('end...')


if __name__ == '__main__':
    lj = LCalculator()
    time = 180
    for i in range(1, time):
        if i == time - 1:
            lj.play(end=True)
        lj.play()

    lj.all_lj
    lj.lian_ji
    lj.currency
